home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7486 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  47 lines

  1. Newsgroups: comp.lang.c
  2. Path: news.netins.net!isac!gg
  3. From: gg@isac.hces.com (Greg Goodrich)
  4. Subject: Re: What is &Variable (declared as: char Variable[10])?
  5. Message-ID: <1996Feb26.211807.28858@isac.hces.com>
  6. Organization: Health Care Expert Systems
  7. X-Newsreader: TIN [version 1.2 PL2]
  8. References: <4gqpa1$3h9@alcor.usc.edu>
  9. Date: Mon, 26 Feb 1996 21:18:07 GMT
  10.  
  11. Abu Wawda (wawda@alcor.usc.edu) wrote:
  12. : I'm having trouble understanding what the address of a static array
  13. : is. For example, if I declare a variable called myarray as:
  14. :     char myarray[10];
  15. : then what could &myarray possibly mean? myarray is not a pointer, so
  16. : &myarray could not possibly be the address of the variable myarray
  17. : (like it would be if I did char* myarray and then asked for &myarray).
  18.  
  19. : Functions such as scanf() allow the following:
  20.  
  21. :     char myarray[10];
  22.  
  23. :     scanf("%s",&myarray);
  24.  
  25. : but I don't understand what scanf() could possibly be taking in the
  26. : second parameter. It can't be: char** since myarray is not a
  27. : pointer. I CAN understand how the following would work:
  28.  
  29. This is because C treats the occurrence of array names as the address of
  30. the array.  Therefore the following are equivalent:
  31.  
  32.     scanf("%s", myarray);
  33.     scanf("%s", &myarray);
  34.  
  35. The thing is, the address is implied when you use an array name.  This
  36. is not so for pointers.  I am not sure why C was incorporated in this
  37. way.  In my humble opinion, it would make it easier and clearer to force
  38. the programmer to put the & in front of array names, the same as you
  39. have to do for any other storage class.
  40.  
  41. Greg.
  42. -- 
  43. _______________________________________
  44.     Greg Goodrich - gg@hces.com
  45.     Software Engineer
  46.     PACE Health Management Systems
  47.